<?php

namespace App\Models;

use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;
use Laravel\Sanctum\HasApiTokens;

class Student extends Authenticatable
{
    use HasApiTokens, Notifiable;

    protected $fillable = [
        'username', 'password', 'name', 'phone', 
        'avatar', 'id_card', 'status'
    ];

    protected $hidden = [
        'password',
        'remember_token',
    ];

    // 关联学生课程
    public function courses()
    {
        return $this->belongsToMany(Course::class, 'student_courses')
                    ->withPivot('start_time', 'progress')
                    ->withTimestamps();
    }

    // 获取课程数量
    public function getCourseCountAttribute()
    {
        return $this->courses()->count();
    }
}
